package com.itheima.reggie.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Slf4j
//当前自动填充的工具类需要交给spring容器管理
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....:" + metaObject);
        long id = Thread.currentThread().getId();
        log.info("MyMetaObjectHandler*********************当前操作线程的id:{}",id);
        metaObject.setValue("createUser", ApplicationContext.getEmpId());
        metaObject.setValue("createTime", LocalDateTime.now());

        metaObject.setValue("updateTime", LocalDateTime.now());

        metaObject.setValue("updateUser", ApplicationContext.getEmpId());


    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....:" + metaObject);
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", ApplicationContext.getEmpId());
    }
}

